package com.decoration.basic.controller.api;

import javax.annotation.Resource;

import com.alibaba.druid.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.decoration.basic.BasicController;
import com.decoration.basic.entity.JsonResult;
import com.decoration.basic.findCondition.DecCaseFindCondition;
import com.decoration.basic.po.DecCaseInfVo;
import com.decoration.basic.po.DecHomePageList;
import com.decoration.basic.service.DecCaseService;
import com.decoration.basic.service.DecPictureService;

@RestController
@RequestMapping("/api")
public class DecCaseController extends BasicController {

	@Resource
	private DecCaseService decCaseservice;

	@Resource
	private DecPictureService decPictureService;

	// 用户首页-获取案例/轮播等列表 分页查询
	@GetMapping("/caselist")
	public JsonResult list(JsonResult jsonResult, DecCaseFindCondition findCondition) {
		setPagerInfo(findCondition);
		DecHomePageList po = new DecHomePageList();
		po.setCarousellist(decPictureService.findCaRousel());
		po.setCaselist(decCaseservice.getCaseList(findCondition));
		Integer count = decCaseservice.getCaseListSize(findCondition);
		jsonResult.setCode(JsonResult.SUCCESS_CODE);
		jsonResult.setMsg("");
		jsonResult.setCount(count);
		jsonResult.setData(po);
		return jsonResult;
	}

	// 用户首页-获取案例内容
	@GetMapping("/casebyid")
	public JsonResult caseid(JsonResult jsonResult, Integer id) {

		DecCaseInfVo list = decCaseservice.findById(id);
		if (list == null || list.getId() == null ) {
			jsonResult.setCode(JsonResult.FAILED_CODE);
			jsonResult.setMsg("获取案例信息失败");
			return jsonResult;
		}
		jsonResult.setCode(JsonResult.SUCCESS_CODE);
		jsonResult.setMsg("获取案例信息成功");
		jsonResult.setCount(1);
		jsonResult.setData(list);
		return jsonResult;
	}

}
